﻿package mortal.game.view.achievement.panel
{
    import Message.Public.*;
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import com.mui.utils.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.achievement.data.*;
    import mortal.game.view.achievement.item.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;

    public class AchievementCurPanel extends GSprite
    {
        private var _totalPointBg:GBitmap;
        private var _totalProgress:BaseProgressBar;
        private var _tipLabel:GTextFiled;
        private var _gotPointLabel:GTextFiled;
        private var _leftBg:ScaleBitmap;
        private var _tabCategoryList:GTileList;
        protected var _flagList:CellsGridSprite;
        private var _totalPanel:AchievementCurTotalPanel;
        private var _littlePanel:AchievementResultPanel;
        private var _lastIndex:int = -1;
        private var _hideIndex:int = 6;
        private var _upcomingType:int = -1;
        private var _flyTime:uint = 0;

        public function AchievementCurPanel()
        {
            return;
        }// end function

        private function init() : void
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.init();
            this._totalPointBg = UIFactory.bitmap(ImagesConst.AchievemenTotalPointTitle, 2, 10, this);
            this._totalProgress = UIFactory.getUICompoment(BaseProgressBar);
            this._totalProgress.setBg(ImagesConst.AchievemntTotalProgressBg, true, 520, 14);
            this._totalProgress.setProgress(ImagesConst.AchievemntTotalProgressBar, true, 1, 1, 518, 12);
            this._totalProgress.setLabel(BaseProgressBar.ProgressBarTextNumber, 207, 2, 100, 20);
            this._totalProgress.setValue(98, 100);
            UIFactory.setObjAttri(this._totalProgress, 110, 15, -1, -1, this);
            this._tipLabel = UIFactory.gTextField("" + Language.getString(70806), 655, 3, 135, 20, this, GlobalStyle.textFormatLv);
            this._gotPointLabel = UIFactory.gTextField("" + Language.getString(70807), 635, 25, 200, 25, this, GlobalStyle.textFormatHuang);
            this._leftBg = UIFactory.bg(0, 45, 165, 507, this);
            this._tabCategoryList = UIFactory.tileList(3, 55, 158, 490, this);
            this._tabCategoryList.direction = GBoxDirection.VERTICAL;
            this._tabCategoryList.setStyle("cellRenderer", AchievementTotalTabCell);
            this._tabCategoryList.verticalGap = 3;
            this._tabCategoryList.rowHeight = 57;
            this._tabCategoryList.columnWidth = 159;
            this._tabCategoryList.columnCount = 1;
            this._tabCategoryList.dataProvider = new DataProvider(Cache.instance.achievent.categoryArr);
            this._tabCategoryList.selectedIndex = 0;
            this._tabCategoryList.configEventListener(Event.CHANGE, this.onTabChangeHd);
            this._totalPanel = UICompomentPool.getUICompoment(AchievementCurTotalPanel) as AchievementCurTotalPanel;
            this._totalPanel.x = 170;
            this._totalPanel.y = 45;
            this.addChild(this._totalPanel);
            this._littlePanel = UICompomentPool.getUICompoment(AchievementResultPanel) as AchievementResultPanel;
            this._littlePanel.x = 170;
            this._littlePanel.y = 45;
            this.addChild(this._littlePanel);
            this.updateTotalPoint(null);
            this.onTabChangeHd(null);
            this._flagList = UIFactory.getUICompoment(CellsGridSprite);
            this._flagList.colNum = 1;
            this._flagList.vCellWid = 100;
            this._flagList.hCellWid = 60;
            this._flagList.genCellFun = UIFactory.getUICompoment;
            this._flagList.genCells(8, AchievementRwCell);
            this._flagList.x = -2;
            this._flagList.y = 52;
            this.addChild(this._flagList);
            this.updateCanGetRw();
            return;
        }// end function

        public function updateCanGetRw() : void
        {
            var _loc_3:AchievementRwCell = null;
            if (isDisposed || this._flagList == null)
            {
                return;
            }
            var _loc_1:* = Cache.instance.achievent.canGetFlagArr;
            var _loc_2:int = 0;
            while (_loc_2 < this._flagList.cellArr.length)
            {
                
                _loc_3 = this._flagList.cellArr[_loc_2];
                if (_loc_2 == 0)
                {
                    if (_loc_1[0] == 0)
                    {
                        _loc_3.updateRw(true);
                    }
                    else
                    {
                        _loc_3.updateRw(false);
                    }
                }
                else if (_loc_1.indexOf(_loc_2) != -1)
                {
                    _loc_3.updateRw(true);
                }
                else
                {
                    _loc_3.updateRw(false);
                }
                _loc_2++;
            }
            return;
        }// end function

        public function updateTotalPoint(param1:Object) : void
        {
            var _loc_2:* = Cache.instance.role.money.achieve;
            var _loc_3:* = AchievementConfig.instance.getTotalPoint();
            this._totalProgress.setValue(_loc_2, _loc_3);
            this._gotPointLabel.text = Language.getStringByParam(70808, (_loc_2 * 10).toString());
            return;
        }// end function

        public function showPanel(param1:int) : void
        {
            if (param1 == 0)
            {
                this._totalPanel.visible = true;
                this._littlePanel.visible = false;
            }
            else
            {
                this._totalPanel.visible = false;
                this._littlePanel.visible = true;
            }
            return;
        }// end function

        private function onTabChangeHd(event:Event) : void
        {
            if (this._tabCategoryList.selectedIndex == 0)
            {
                this.showPanel(0);
            }
            else
            {
                this.showPanel(1);
            }
            if (this._lastIndex != this._tabCategoryList.selectedIndex)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.AchievementCategorySelect, this._tabCategoryList.selectedIndex));
            }
            this._lastIndex = this._tabCategoryList.selectedIndex;
            return;
        }// end function

        public function updateAfterTabCk() : void
        {
            if (this._upcomingType == -1)
            {
                this._littlePanel.updateByTabIndex(this._tabCategoryList.selectedIndex, true);
            }
            else
            {
                this._littlePanel.turnToPageByType(this._tabCategoryList.selectedIndex, this._upcomingType);
                this._upcomingType = -1;
            }
            return;
        }// end function

        public function openTabByIndex(param1:int, param2:int = 0) : void
        {
            this._tabCategoryList.selectedIndex = param1;
            this._upcomingType = param2;
            this.onTabChangeHd(null);
            return;
        }// end function

        public function initCategory() : void
        {
            var _loc_1:* = Cache.instance.achievent.overViewArr;
            this._totalPanel.initCategory(_loc_1);
            return;
        }// end function

        public function initUpComing() : void
        {
            var _loc_1:* = Cache.instance.achievent.upComingArr;
            this._totalPanel.initUpComing(_loc_1);
            return;
        }// end function

        public function updateCategory(param1:SAchievementCategory) : void
        {
            if (param1 == null)
            {
                return;
            }
            this._totalPanel.flyCatoryIcon();
            this._totalPanel.updateCategoryByInfo(param1);
            return;
        }// end function

        public function updateType(param1:SAchievementType) : void
        {
            if (this._littlePanel.flyTypeIcon() == false)
            {
                this._littlePanel.updateByTabIndex(this._tabCategoryList.selectedIndex, false);
            }
            else
            {
                this._flyTime = setTimeout(this.updateAfterFly, 500);
            }
            return;
        }// end function

        private function updateAfterFly() : void
        {
            clearTimeout(this._flyTime);
            this._flyTime = 0;
            if (this._littlePanel)
            {
                this._littlePanel.updateByTabIndex(this._tabCategoryList.selectedIndex, false);
            }
            return;
        }// end function

        public function updateRW() : void
        {
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            if (this._flyTime != 0)
            {
                clearTimeout(this._flyTime);
                this._flyTime = 0;
            }
            this._totalPointBg.dispose(param1);
            this._totalPointBg = null;
            this._totalProgress.dispose(param1);
            this._totalProgress = null;
            this._tipLabel.dispose(param1);
            this._tipLabel = null;
            this._gotPointLabel.dispose(param1);
            this._gotPointLabel = null;
            this._leftBg.dispose(param1);
            this._leftBg = null;
            this._tabCategoryList.dispose(param1);
            this._tabCategoryList = null;
            this._totalPanel.dispose(param1);
            this._totalPanel = null;
            this._littlePanel.dispose(param1);
            this._littlePanel = null;
            this._flagList = null;
            return;
        }// end function

    }
}
